//
//  RechargeVC.m
//  MRBang
//
//  Created by 铅笔 on 16/4/20.
//  Copyright © 2016年 杭州易网新科技. All rights reserved.
//

#import "RechargeVC.h"
#import "MyBankCardVC.h"

#define CELLHEIGHT 125*PROPORTION_WIDTH

@interface RechargeVC ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong) UITableView *tableView_Recharge;

@property (nonatomic,strong) UITextField *textField_price;
@property (nonatomic,strong) UITextField *textField_pwd;

@end

@implementation RechargeVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"充值";
    
    self.view.backgroundColor = COLOR_EVERYVIEWBG;
    
    [self initWithDetailTableViewSubviews];
}

#pragma mark --- 创建明细表
- (void) initWithDetailTableViewSubviews
{
    self.tableView_Recharge = [[UITableView alloc] initWithFrame:CGRectMake(0,0, kScreenWidth,170*PROPORTION_WIDTH+CELLHEIGHT*3)];
    [self.view addSubview:self.tableView_Recharge];
    self.tableView_Recharge.dataSource = self;
    self.tableView_Recharge.delegate = self;
    self.tableView_Recharge.showsVerticalScrollIndicator = NO;
    self.tableView_Recharge.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView_Recharge.scrollEnabled = NO;
    self.tableView_Recharge.backgroundColor = COLOR_EVERYVIEWBG;
 
    //button  recharge
    UIButton *button_recharge = [[UIButton alloc] initWithFrame:CGRectMake(30*PROPORTION_WIDTH,self.tableView_Recharge.bottom+55*PROPORTION_WIDTH, kScreenWidth-30*2*PROPORTION_WIDTH, 95*PROPORTION_WIDTH)];
    [self.view addSubview:button_recharge];
    [button_recharge setImage:[UIImage imageNamed:@"button_sureRechange"] forState:UIControlStateNormal];
    [button_recharge addTarget:self action:@selector(rechargeAndWithdrawsAction) forControlEvents:UIControlEventTouchUpInside];
    
}

//确认充值
- (void) rechargeAndWithdrawsAction
{

}

#pragma mark --- UITableViewDataSource
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellMyTradingRecordID = @"cellMyTradingRecordID";
    UITableViewCell *cell_recharge = [tableView cellForRowAtIndexPath:indexPath];
    if (cell_recharge == nil) {
        cell_recharge = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellMyTradingRecordID];
    }
    
    cell_recharge.selectionStyle = UITableViewCellSelectionStyleNone;
    
    //label
    UILabel *label_leftTitle = [[UILabel alloc] init];
    [cell_recharge.contentView addSubview:label_leftTitle];
    label_leftTitle.font = [UIFont systemFontOfSize:24*PROPORTION_WIDTH];
    label_leftTitle.textColor = [BaseViewController colorWithHexString:@"#384056"];
    
    if (indexPath.row==0) {
        label_leftTitle.frame = CGRectMake(44*PROPORTION_WIDTH, 50*PROPORTION_WIDTH, 130*PROPORTION_WIDTH, 31*PROPORTION_WIDTH);
            label_leftTitle.text = @"选择银行卡";
        //button
        UIButton *button_rightArrow = [[UIButton alloc] initWithFrame:CGRectMake(kScreenWidth-50*PROPORTION_WIDTH, 47*PROPORTION_WIDTH, 30*PROPORTION_WIDTH, 34*PROPORTION_WIDTH)];
        [cell_recharge.contentView addSubview:button_rightArrow];
        [button_rightArrow setImage:[UIImage imageNamed:@"return_right"] forState:UIControlStateNormal];
        
    }
    if (indexPath.row==1) {
        
        cell_recharge.backgroundColor = [BaseViewController colorWithHexString:@"#eeeff1"];
        label_leftTitle.frame = CGRectMake(44*PROPORTION_WIDTH, 16*PROPORTION_WIDTH, kScreenWidth-44*PROPORTION_WIDTH*2, 22*PROPORTION_WIDTH);
        label_leftTitle.text = @"该卡本次最多可充值100,000.00元";
        
    }
    if (indexPath.row==2) {
        
        UIView *view_line = [[UIView alloc] initWithFrame:CGRectMake(27*PROPORTION_WIDTH, CELLHEIGHT-1, kScreenWidth, 1.0)];
        [cell_recharge.contentView addSubview:view_line];
        view_line.backgroundColor = [BaseViewController colorWithHexString:@"#EEEFF1"];
        
        label_leftTitle.frame = CGRectMake(44*PROPORTION_WIDTH, 50*PROPORTION_WIDTH, 58*PROPORTION_WIDTH, 39*PROPORTION_WIDTH);
        label_leftTitle.text = @"金额";
        
        //textfield
        self.textField_price = [[UITextField alloc] initWithFrame:CGRectMake(label_leftTitle.right+35*PROPORTION_WIDTH, label_leftTitle.y, 550*PROPORTION_WIDTH, label_leftTitle.height)];
        [cell_recharge.contentView addSubview:self.textField_price];
        self.textField_price.placeholder = @"请输入充值金额";
        self.textField_price.font = [UIFont systemFontOfSize:24*PROPORTION_WIDTH];

    }
    if (indexPath.row==3) {
        
        label_leftTitle.frame = CGRectMake(44*PROPORTION_WIDTH, 50*PROPORTION_WIDTH, 58*PROPORTION_WIDTH, 39*PROPORTION_WIDTH);
        label_leftTitle.text = @"密码";
        
        //textfield
        self.textField_pwd = [[UITextField alloc] initWithFrame:CGRectMake(label_leftTitle.right+35*PROPORTION_WIDTH, label_leftTitle.y, 550*PROPORTION_WIDTH, label_leftTitle.height)];
        [cell_recharge.contentView addSubview:self.textField_pwd];
        self.textField_pwd.placeholder = @"请输入交易密码";
        self.textField_pwd.font = [UIFont systemFontOfSize:24*PROPORTION_WIDTH];

    }
    
    return cell_recharge;
    
}

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.row==0) {
        MyBankCardVC *myCardView = [[MyBankCardVC alloc] init];
        [self.navigationController pushViewController:myCardView animated:NO];
    }
    
    else
    {
        //添加手势
        UITapGestureRecognizer *tableViewGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(commentTableViewTouchInSide)];
        [self.tableView_Recharge addGestureRecognizer:tableViewGesture];
    }
}


- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==1) {
        return 50*PROPORTION_WIDTH;
    }
    else
    {
      return CELLHEIGHT;
    }
}


#pragma mark  --- 点击tableView 收回键盘
- (void)commentTableViewTouchInSide{
    [self.textField_price resignFirstResponder];
    [self.textField_pwd resignFirstResponder];
}

- (void) touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


@end
